#define MIN(x, y) ((x) < (y) ? (x) : (y))

void show(int** grid, int gridSize, int* gridColSize)
{
    int h = gridSize;
    int w = *gridColSize;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            printf("%3d", grid[y][x]);
        }
        printf("\n");
    }
}

int minPathSum(int** grid, int gridSize, int* gridColSize){
    int h = gridSize;
    int w = *gridColSize;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (y == 0 && x == 0) {
                continue;
            } else if (y == 0) {
                grid[y][x] += grid[y][x - 1];
            } else if (x == 0) {
                 grid[y][x] += grid[y - 1][x];
            } else {
                grid[y][x] += MIN(grid[y][x - 1], grid[y - 1][x]);
            }
        }
    }
    return grid[h - 1][w - 1];
}

